//============================================================================
// Name        : BestTry.cpp
// Author      : Marc Petroff
// Version     :
// Copyright   : MPRights (2014)
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <cstdlib>
#include <iostream>
//#include <dlfcn>

#undef MP_CRYPTLIB_INTERNAL_DECLARATION
#include "mp_crypt.h"


enum mp_crypt_error {
	MP_CRYPTERR_NO_ERR = 1,                    //!< MP_CRYPTERR_NO_ERR
	MP_CRYPTERR_EMPTY_PUBLIC_STRING = -8892,   //!< MP_CRYPTERR_EMPTY_PUBLIC_STRING
	MP_CRYPTERR_TOO_LONG_PUBLIC_STRING = -8893,//!< MP_CRYPTERR_TOO_LONG_PUBLIC_STRING
	MP_CRYPTERR_LIBRARY_DEPENDANCY_FAIL = -8894//!< MP_CRYPTERR_LIBRARY_DEPENDANCY_FAIL
} e;




/**
 * La variable globale qui contient le code erreur basé sur l'enum
 */
mp_crypt_error mp_errno;

using namespace std;

int main() {

	void *l[4];
	char **d;
	int u;
	void *library_handle;


/*
library_handle = dlopen("libMP_cryptlib.so.0.08.0005",RTLD_DI_LMID);

		// TODO implement the library !

if (library_handle == NULL) {
 dlsym(library_handle,"mp_getEncrypt");
}
*/

struct B {
	char **j;
	int z;
} b,e;


B *s;
d = (char **)calloc(2,sizeof(char));
d[0] = (char *)calloc(255,sizeof(char));
d[1] = (char *)calloc(255,sizeof(char));

/*if ((u = mp_getVersion(d[0]))) {
	std::cout << (char *)d[0] << std::endl;
}*/

//l = calloc(2,sizeof(char));
l[0] = calloc(255,sizeof(char));
l[1] = calloc(255,sizeof(char));
l[2] = calloc(255,sizeof(char));
l[3] = NULL;
strcpy((char *)l[0],"Somestuff");
strcpy((char *)l[1],"Unwantedcrap");

b.j = (char **)l;
e.j = (char **)l;
//setenv("LD_LIBRARY_PATH","/home/marc/workspace/BestTry/Release:$LD_LIBRARY_PATH",)

e.z = mp_getVersion(d);
free(d);
d = (char **)calloc(2,sizeof(char));
d[0] = (char *)calloc(255,sizeof(char));
d[1] = (char *)calloc(255,sizeof(char));

strcat(d[0],"Long words reversed");

e.z = mp_getEncrypt(d[0]);

strcpy(e.j[1],"Morecrap");
s->j = (char **)l;
strcpy((char *)l[2],"After insert");

	cout << "[GB_en]Hello World " << d[0] << " returned int : " << e.z << "detailed version :" <<  d[1] << b.j[0] << " " << e.j[1] << " " << s->j[2] << endl; // prints [GB_en]Hello World
    cout << "bool:\t\t" << sizeof(bool) << " bytes" << endl;
    cout << "char:\t\t" << sizeof(char) << " bytes" << endl;
    cout << "wchar_t:\t" << sizeof(wchar_t) << " bytes" << endl;
    cout << "short:\t\t" << sizeof(short) << " bytes" << endl;
    cout << "int:\t\t" << sizeof(int) << " bytes" << endl;
    cout << "long:\t\t" << sizeof(long) << " bytes" << endl;
    cout << "float:\t\t" << sizeof(float) << " bytes" << endl;
    cout << "double:\t\t" << sizeof(double) << " bytes" << endl;
   // using namespace mp_crypt_h;
    cout << "sctruct:\t\t" << mp_crypt_h::mp_crypt_types.MP_CRYPTTYPE_REVERSE   << " value" << endl;
    cout << "summ:\t\t" << mp_setEncryptType((int)mp_crypt_h::mp_crypt_types.MP_CRYPTTYPE_REVERSE)  << " value" << endl;
    cout << "summ should faill (9999):\t\t" << mp_setEncryptType(31)  << " value" << endl;
   cout << "long double:\t" << sizeof(long double) << " bytes" << endl;
// mp_setEncryptType
	/*Free the memory tha was calloc'd'*/
	free(d);
	free(l[0]);free(l[1]);free(l[2]);free(l[3]);
	return 0;
}
